package com.zensation.ticklemepanda;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.zensation.ticklemepanda.util.TickleMePandaSharedPreference;

public class WinGameActivity extends Activity implements OnClickListener {

	private Button shareBtn;
	private Button exitBtn;
	private Button playAgainBtn;
	private TickleMePandaSharedPreference funnyAnimalGameSharedPreference;
	private static String shareMsgSubject;
	private static String shareMsgContent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.page_win_game);

		funnyAnimalGameSharedPreference = TickleMePandaSharedPreference.getInstance(this);
		shareBtn = (Button) findViewById(R.id.share_btn);
		exitBtn = (Button) findViewById(R.id.exit_btn);
		playAgainBtn = (Button) findViewById(R.id.play_again_btn);
		shareBtn.setOnClickListener(this);
		exitBtn.setOnClickListener(this);
		playAgainBtn.setOnClickListener(this);

		shareMsgSubject = getResources().getString(R.string.shared_msg_subject);
		shareMsgContent = getResources().getString(R.string.shared_msg_content);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v == shareBtn) {
			shareContent(shareMsgSubject, shareMsgContent);
		} else if (v == exitBtn) {
			funnyAnimalGameSharedPreference.putScoreValue(0);
			funnyAnimalGameSharedPreference.setExitGame(true);
			finish();
		} else if (v == playAgainBtn) {
			funnyAnimalGameSharedPreference.putScoreValue(0);
			funnyAnimalGameSharedPreference.setPlayAgain(true);
			finish();
		}
	}

	public void shareContent(String subject,String content) {
		Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
		// set the type
		shareIntent.setType("text/plain");
		// add a subject
		shareIntent
				.putExtra(android.content.Intent.EXTRA_SUBJECT,
						subject);
		// build the body of the message to be shared
		String shareMessage = content;
		// add the messagelăm
		shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareMessage);
		// start the chooser for sharing
		startActivity(Intent.createChooser(shareIntent, "Share"));
	}
}
